﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Entities;
using Context;
namespace WCF_ListenMusic.Services.Module_Song.Admin
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ManageMemberService" in code, svc and config file together.
    public class ManageMemberService : IManageMemberService
    {
        Context.Connect_DBDataContext context = new Context.Connect_DBDataContext();
        public List<MembershipUserRole> getAllMembershipUser()
        {
            try {
                var q = from a in context.MembershipUserRoles
                        where !a.UserName.Equals("ClientUser") && !a.UserName.Equals("admin") 
                        select a;
                return q.ToList();
            }
            catch (Exception e) { throw new FaultException(e.Message);}
        }


        public bool LockOrUnlockAccount(Guid userId)
        {
            try
            {
                var q = from a in context.aspnet_Memberships
                        where a.UserId.Equals(userId)
                        select a;
                aspnet_Membership old = q.Single();
                if (old.IsLockedOut == false)                
                    old.IsLockedOut = true;
                else
                    old.IsLockedOut = false;                
                context.SubmitChanges();
                return true;
            }
            catch (Exception e) { return false; throw new FaultException(e.Message); }
        }
    }
}
